﻿using Main.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main.Engine
{
    partial class ServiceLocator : IServiceLocator    
    {
        public T Locate<T>() where T : IService
        {
            if (!SERVICES.ContainsKey(typeof(T)))
                throw new NotImplementedException(string.Format("The requested service [{0}] has not been implemeted or registered", typeof(T).Name));
            else
                return (T)SERVICES[typeof(T)];
        }

        public void Register<T>(T service) where T : IService
        {
            if (!SERVICES.ContainsKey(typeof(T)))
                throw new ArgumentException(string.Format("The requested service [{0}] has already been registered", typeof(T).Name));
            else
                SERVICES.Add(typeof(T), service);
        }

        public void Replace<T>(T service) where T : IService
        {
            if (SERVICES.ContainsKey(typeof(T)))
                SERVICES[typeof(T)] = service;
            else
                SERVICES.Add(typeof(T), service);
        }

        public bool Contains<T>() where T : IService
        {
            return SERVICES.ContainsKey(typeof(T));
        }
    }
}
